package cn.jbolt.admin.globalconfig;

import cn.jbolt.core.api.JBoltApiBaseController;
import cn.jbolt.core.api.httpmethod.JBoltHttpGet;
import cn.jbolt.core.api.httpmethod.JBoltHttpPost;
import cn.jbolt.core.model.GlobalConfigType;
import cn.jbolt.core.model.base.JBoltBaseModel;
import cn.jbolt.core.permission.CheckPermission;
import cn.jbolt.core.permission.UnCheckIfSystemAdmin;
import cn.jbolt.core.service.JBoltGlobalConfigTypeService;
import cn.jbolt.core.service.base.JBoltBaseService;
import cn.jbolt.extend.permission.PermissionKey;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.core.paragetter.Para;
import com.jfinal.plugin.activerecord.tx.Tx;

@UnCheckIfSystemAdmin
@CheckPermission(PermissionKey.GLOBALCONFIG)
@Path("/api/admin/globalConfigType")
public class GlobalConfigTypeAdminController extends JBoltApiBaseController {
    @Inject
    private JBoltGlobalConfigTypeService service;

    /**
     * 单个详情信息读取
     */
    @JBoltHttpGet
    public void index(){
        renderJBoltApiRet(findModelById());
    }

    /**
     * admin数据源
     */
    public void datas() {
        renderJBoltApiSuccessWithData(service.getAdminList());
    }

    /**
     *保存
     */
    @Before(Tx.class)
    @JBoltHttpPost
    public void save(@Para("")GlobalConfigType globalConfigType) {
        renderJBoltApiRet(service.save(globalConfigType));
    }

    /**
     *更新
     */
    @Before(Tx.class)
    @JBoltHttpPost
    public void update(@Para("")GlobalConfigType globalConfigType) {
        renderJBoltApiRet(service.update(globalConfigType));
    }

    /**
     *删除
     */
    @Before(Tx.class)
    @JBoltHttpGet
    public void delete() {
        renderJBoltApiRet(service.delete(getId()));
    }

    /**
     * 排序 上移
     */
    @Before(Tx.class)
    @JBoltHttpGet
    public void up() {
        renderJBoltApiRet(service.doUp(getId()));
    }

    /**
     * 排序 下移
     */
    @Before(Tx.class)
    @JBoltHttpGet
    public void down() {
        renderJBoltApiRet(service.doDown(getId()));
    }

    /**
     * 排序初始化
     */
    @Before(Tx.class)
    @JBoltHttpGet
    public void initRank() {
        renderJBoltApiRet(service.initRank());
    }

    @Override
    protected JBoltBaseService<? extends JBoltBaseModel<?>> getModelService() {
        return service;
    }
}
